#include"GameLogicController.h"
#include"../ServerMaster.h"
#include"../GameServer.h"
#include"../event/SignalManager.h"
#include"../MessageIDConst.h"
#include"../UserBaseController.h"
#include"../Common.h"

GameLogicController::GameLogicController(Object* master)
{
	m_master = master;
	SignalManager::getInstance()->add(ID_C2S_MonsterLeaveFight, handler(this, SEL_EVENTFUNC(GameLogicController::C2S_MonsterLeaveFight)));
	SignalManager::getInstance()->add(ID_C2S_MonsterFight, handler(this, SEL_EVENTFUNC(GameLogicController::C2S_MonsterFight)));
}

GameLogicController::~GameLogicController()
{
}

void GameLogicController::C2S_MonsterTrack(Json::Value& message)
{
	auto master = dynamic_cast<ServerMaster*>(m_master);
	auto sceneId = message["sceneId"].asInt();
	auto monsterId = message["monsterId"].asInt();
	auto trackId = message["trackId"].asInt();
	auto scene = master->getGameScene(sceneId);

}

void GameLogicController::C2S_MonsterFight(Json::Value& message)
{
	auto master = dynamic_cast<ServerMaster*>(m_master);
	auto sceneId = message["sceneId"].asInt();
	auto monsterId = message["monsterId"].asInt();
	auto fightId = message["fightId"].asInt();
	auto scene = master->getGameScene(sceneId);
	scene->monsterFight(monsterId, fightId);
}

void GameLogicController::C2S_LeaveMonsterTrack(Json::Value& message)
{
}

void GameLogicController::C2S_MonsterLeaveFight(Json::Value& message)
{
	auto master = dynamic_cast<ServerMaster*>(m_master);
	auto userBase = master->getModule<UserBaseController>();
	auto recvSock = message[RECV_SOCK].asInt64();
	auto userId = userBase->geUserIdBySock(recvSock);
	auto sceneId = message["sceneId"].asInt();
	auto monsterId = message["monsterId"].asInt();
	auto success = message["success"].asInt();
	auto scene = master->getGameScene(sceneId);
	scene->monsterFightResult(userId, monsterId, success);
}
